package class231020013;

public class MaxVisitorsCalculation {

	void search(Journal journal){
		
		int[] times = new int[journal.visits.length*2];
		
		for( int i = 0 ; i < journal.visits.length ; i++){
			
			times[i] = journal.visits[i].arrivals.getTime();
			
			int tmp = -journal.visits[i].dispatches.getTime();
			
			if (tmp == 0){
				times[i+journal.visits.length] = -(24*60);
			}
			else{
				times[i+journal.visits.length] = tmp;
			}

		}
		
		times = sorting(times);
		

		int maxCounter = 0;
		int count = 0;
		
		int timeArrivals = 0;
		int timeDispatches = 0;
		
		for(int i =0; i<times.length;i++){
			if(times[i] >=0){
				count++;
				timeArrivals=times[i];
			}else{
				count--;
				timeDispatches=times[i];
			}
			if(count>maxCounter){
				maxCounter = count;
			}
			
		}
		
		System.out.println("maxCounter ["+maxCounter +"] - timeArrivals ["+ timeArrivals/60 +"/"+ timeArrivals%24 + "] - timeDispatches ["+ Math.abs(timeDispatches/60) +"/"+ timeDispatches%24 + "]");

	}
	
	int[] sorting(int[] times){
		
		for( int i = times.length - 1 ; i >= 0  ; i--){
			for (int j = 0 ; j < i  ; j ++){
				if ( Math.abs(times[j]) > Math.abs(times[j+1])){
					int tmp = times[j];
					times[j] = times[j+1];
					times[j+1] = tmp;
				}
			}
		}
		return times;
	}
	
	
	
	
		
}
